#pragma once
#ifndef _MY_DIALOG_H_
#define _MY_DIALOG_H_
#ifdef WIN32
#pragma execution_character_set("utf-8")
#endif // WIN32

#include <qwidget.h>
#include <QtWidgets/qdialog.h>
#include <QKeyEvent>
#include <qmovie.h>
#include <qpixmap.h>
#include <QMutex>


namespace Ui {
    class LoadingDialog;
    class MessageDialog;

}

/// <summary>
/// 等待对话框
/// </summary>
class MyLoading : public QDialog {

    Q_OBJECT

public:

    /// <summary>
    /// 显示窗口
    /// </summary>
    static void startLoading(QWidget* parent = nullptr, QString msg = "请稍后...");


    /// <summary>
    /// 关闭对话框
    /// </summary>
    static void stopLoading();


//private:

    /// <summary>
    /// 创建对话框
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="parent"></param>
    MyLoading(QWidget* parent = nullptr);

    /// <summary>
    /// 设置显示的信息
    /// </summary>
    /// <param name="msg"></param>
    void setMessage(QString msg);

    ~MyLoading() { delete m_ui; };

    //隐藏拷贝构造函数和复制函数
    MyLoading(const MyLoading& conf) = delete;

    const MyLoading& operator=(const MyLoading& conf) = delete;

//protected:

    /// <summary>
    /// 重写keyPressEvent事件，禁用键盘快捷键，防止点击键盘上的按钮后退出对话框
    /// </summary>
    /// <param name="event"></param>
    //void keyPressEvent(QKeyEvent* event) override { };

private:

    Ui::LoadingDialog* m_ui;

    static MyLoading* m_instance;

    static QMutex m_mutex;

};



/// <summary>
/// 提示，警告，错误，询问对话框
/// </summary>
class MyMessageBox : public QDialog {

    Q_OBJECT

public:

    static int information(QWidget* parent, QString text = QString(), QString acceptBtn = QString(), QString rejectBtn = QString());

    static int warning(QWidget* parent, QString text = QString(), QString acceptBtn = QString(), QString rejectBtn = QString());

    static int error(QWidget* parent, QString text = QString(), QString acceptBtn = QString(), QString rejectBtn = QString());

    static int question(QWidget* parent, QString text = QString(), QString acceptBtn = QString(), QString rejectBtn = QString());


private:

    MyMessageBox(QWidget* parent, QPixmap& icon, QString text = QString(), QString acceptBtn = QString(), QString rejectBtn = QString());

    ~MyMessageBox() {};

    MyMessageBox(const MyMessageBox& conf) { };

    const MyMessageBox& operator=(const MyMessageBox& conf) { return *this; };

protected:

    void keyPressEvent(QKeyEvent* event) override { };

private:

    Ui::MessageDialog* m_ui = nullptr;


};


///// <summary>
///// 输入对话框
///// </summary>
//class MyInputDialog : public QDialog {
//    
//    Q_OBJECT
//
//public:
//
//    qint64 getIntVal();
//
//    double getDoubleVal();
//
//    QString getStringVal();
//
//    QString getTextVal();
//
//private:
//
//    MyInputDialog();
//
//    ~MyInputDialog();
//
//
//
//};
#endif